/*
 * HideMe: hide files on a cellphone
 * Copyright (C) 2009  Eduard Martínez
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package hideme;

import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStoreException;
import org.netbeans.microedition.lcdui.SplashScreen;
import org.netbeans.microedition.lcdui.WaitScreen;
import org.netbeans.microedition.util.SimpleCancellableTask;

public class HideMe extends MIDlet implements CommandListener {


    private boolean midletPaused = false;
   // private final Hashtable recordIds = new Hashtable();
    private final Vector recordIds = new Vector();
    private final Options options = new Options();

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private java.util.Hashtable __previousDisplayables = new java.util.Hashtable();
    private List main;
    private Alert pinChangedAlert;
    private Form pinForm;
    private Spacer spacer;
    private StringItem pinFormString;
    private TextField pin;
    private HideMeBrowser hideMeBrowser;
    private Form help;
    private StringItem stringItem;
    private Form changePin;
    private StringItem pinTip;
    private TextField oldPin;
    private TextField newPin1;
    private TextField newPin2;
    private Alert fileAddedAlert;
    private List fileList;
    private WaitScreen waitScreen;
    private Alert empty_list;
    private Alert error_hidding;
    private Alert success_hidding;
    private Command changePingCommand;
    private Command okCommand1;
    private Command exitCommand1;
    private Command exitCommand;
    private Command helpCommand;
    private Command backCommand;
    private Command cancelCommand;
    private Command okCommand;
    private Command backCommand2;
    private Command addCommand;
    private Command backCommand1;
    private Command removeCommand;
    private Image hideMeLogo;
    private SimpleCancellableTask hideMeTask;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The HideMe constructor.
     */
    public HideMe() throws RecordStoreException {
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    /**
     * Switches a display to previous displayable of the current displayable.
     * The <code>display</code> instance is obtain from the <code>getDisplay</code> method.
     */
    private void switchToPreviousDisplayable() {
        Displayable __currentDisplayable = getDisplay().getCurrent();
        if (__currentDisplayable != null) {
            Displayable __nextDisplayable = (Displayable) __previousDisplayables.get(__currentDisplayable);
            if (__nextDisplayable != null) {
                switchDisplayable(null, __nextDisplayable);
            }
        }
    }
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        String storedPin = options.getPin();
        if("".equals(storedPin)){
            switchDisplayable(null, getMain());
        }else{
            switchDisplayable(null, getPinForm());
        }
//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        Displayable __currentDisplayable = display.getCurrent();
        if (__currentDisplayable != null  &&  nextDisplayable != null) {
            __previousDisplayables.put(nextDisplayable, __currentDisplayable);
        }
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == changePin) {//GEN-BEGIN:|7-commandAction|1|60-preAction
            if (command == cancelCommand) {//GEN-END:|7-commandAction|1|60-preAction
                // write pre-action user code here
                switchDisplayable(null, getMain());//GEN-LINE:|7-commandAction|2|60-postAction
                // write post-action user code here
            } else if (command == okCommand) {//GEN-LINE:|7-commandAction|3|58-preAction
                String storedPin = options.getPin();
                String old = getOldPin().getString();
                String newPin = getNewPin1().getString();
                if(!old.equals(storedPin)){
                    getPinChangedAlert().setString("Incorrect pin");
                    getPinChangedAlert().setTitle("Pin error");
                    getPinChangedAlert().setType(AlertType.ERROR);
                    switchDisplayable(getPinChangedAlert(), getChangePin());
                    return;
                }else if(!newPin.equals(getNewPin2().getString())){
                    getPinChangedAlert().setString("New pin mismatch");
                    getPinChangedAlert().setTitle("Pin error");
                    getPinChangedAlert().setType(AlertType.ERROR);
                    switchDisplayable(getPinChangedAlert(), getChangePin());
                    return;
                }
                options.setPin(newPin);
                getPinChangedAlert().setString("Pin changed");
                getPinChangedAlert().setTitle("Pin");
                getPinChangedAlert().setType(AlertType.INFO);
                switchDisplayable(getPinChangedAlert(), getMain());//GEN-LINE:|7-commandAction|4|58-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|5|88-preAction
        } else if (displayable == fileList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|5|88-preAction
                // write pre-action user code here
                fileListAction();//GEN-LINE:|7-commandAction|6|88-postAction
                // write post-action user code here
            } else if (command == addCommand) {//GEN-LINE:|7-commandAction|7|93-preAction
                // write pre-action user code here
                switchDisplayable(null, getHideMeBrowser());//GEN-LINE:|7-commandAction|8|93-postAction
                // write post-action user code here
            } else if (command == backCommand1) {//GEN-LINE:|7-commandAction|9|91-preAction
                // write pre-action user code here
                switchDisplayable(null, getMain());//GEN-LINE:|7-commandAction|10|91-postAction
                // write post-action user code here
            } else if (command == removeCommand) {//GEN-LINE:|7-commandAction|11|107-preAction
                deleteFile(fileList.getSelectedIndex());
                switchDisplayable(null, getFileList());//GEN-LINE:|7-commandAction|12|107-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|13|53-preAction
        } else if (displayable == help) {
            if (command == backCommand) {//GEN-END:|7-commandAction|13|53-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|14|53-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|15|171-preAction
        } else if (displayable == hideMeBrowser) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|15|171-preAction
                // write pre-action user code here
                hideMeBrowserAction();//GEN-LINE:|7-commandAction|16|171-postAction
                // write post-action user code here
            } else if (command == backCommand2) {//GEN-LINE:|7-commandAction|17|178-preAction
                // write pre-action user code here
                switchDisplayable(null, getFileList());//GEN-LINE:|7-commandAction|18|178-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|20-preAction
        } else if (displayable == main) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|19|20-preAction
                // write pre-action user code here
                mainAction();//GEN-LINE:|7-commandAction|20|20-postAction
                // write post-action user code here
            } else if (command == changePingCommand) {//GEN-LINE:|7-commandAction|21|142-preAction
                // write pre-action user code here
                switchDisplayable(null, getChangePin());//GEN-LINE:|7-commandAction|22|142-postAction
                // write post-action user code here
            } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|23|25-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|24|25-postAction
                // write post-action user code here
            } else if (command == helpCommand) {//GEN-LINE:|7-commandAction|25|47-preAction
                // write pre-action user code here
                switchDisplayable(null, getHelp());//GEN-LINE:|7-commandAction|26|47-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|27|158-preAction
        } else if (displayable == pinForm) {
            if (command == exitCommand1) {//GEN-END:|7-commandAction|27|158-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|28|158-postAction
                // write post-action user code here
            } else if (command == okCommand1) {//GEN-LINE:|7-commandAction|29|156-preAction
                // write pre-action user code here
                String storedPin = options.getPin();
                if(!storedPin.equals(getPin().getString())){
                    getPinChangedAlert().setTitle("Pin error");
                    getPinChangedAlert().setString("Incorrect pin");
                    switchDisplayable(getPinChangedAlert(), getPinForm());
                    return;
                }
                switchDisplayable(null, getMain());//GEN-LINE:|7-commandAction|30|156-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|31|126-preAction
        } else if (displayable == waitScreen) {
            if (command == WaitScreen.FAILURE_COMMAND) {//GEN-END:|7-commandAction|31|126-preAction
                // write pre-action user code here
                switchDisplayable(getError_hidding(), getMain());//GEN-LINE:|7-commandAction|32|126-postAction
                // write post-action user code here
            } else if (command == WaitScreen.SUCCESS_COMMAND) {//GEN-LINE:|7-commandAction|33|125-preAction
                // write pre-action user code here
                switchDisplayable(null, getSuccess_hidding());//GEN-LINE:|7-commandAction|34|125-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|35|7-postCommandAction
        }//GEN-END:|7-commandAction|35|7-postCommandAction
        // write post-action user code here
        if (displayable == hideMeBrowser){
            if(command == HideMeBrowser.SELECT_FILE_COMMAND){
                String file = hideMeBrowser.getCurrentFolder() + hideMeBrowser.getCurrentFile();
                addSelected(file);
                getFileAddedAlert().setString(file);
                switchDisplayable(getFileAddedAlert(), getFileList());
            }else if (command == HideMeBrowser.SELECT_FOLDER_COMMAND){
                String file = hideMeBrowser.getCurrentFolder();
                addSelected(hideMeBrowser.getCurrentFolder());
                getFileAddedAlert().setString(file);
                switchDisplayable(getFileAddedAlert(), getFileList());
            }

        }
    }//GEN-BEGIN:|7-commandAction|36|
    //</editor-fold>//GEN-END:|7-commandAction|36|








    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: main ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of main component.
     * @return the initialized component instance
     */
    public List getMain() {
        if (main == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            main = new List("HideMe", Choice.IMPLICIT);//GEN-BEGIN:|18-getter|1|18-postInit
            main.append("Hide files", null);
            main.append("Unhide files", null);
            main.append("Change file selection", null);
            main.addCommand(getExitCommand());
            main.addCommand(getHelpCommand());
            main.addCommand(getChangePingCommand());
            main.setCommandListener(this);
            main.setSelectedFlags(new boolean[] { false, false, false });//GEN-END:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return main;
    }
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: mainAction ">//GEN-BEGIN:|18-action|0|18-preAction
    /**
     * Performs an action assigned to the selected list element in the main component.
     */
    public void mainAction() {//GEN-END:|18-action|0|18-preAction
        // enter pre-action user code here
        String __selectedString = getMain().getString(getMain().getSelectedIndex());//GEN-BEGIN:|18-action|1|79-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Hide files")) {//GEN-END:|18-action|1|79-preAction
                // write pre-action user code here
                if(getFileList().size() == 0){
                    switchDisplayable(getEmpty_list(), this.getMain());
                    return;
                }
                getWaitScreen().setTask(new Hider(true));
                getWaitScreen().setText("Hiding files...");
                switchDisplayable(null, getWaitScreen());//GEN-LINE:|18-action|2|79-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Unhide files")) {//GEN-LINE:|18-action|3|41-preAction
                // write pre-action user code here
                if(getFileList().size() == 0){
                    switchDisplayable(getEmpty_list(), this.getMain());
                    return;
                }
                getWaitScreen().setTask(new Hider(false));
                getWaitScreen().setText("Unhiding files...");
                switchDisplayable(null, getWaitScreen());//GEN-LINE:|18-action|4|41-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Change file selection")) {//GEN-LINE:|18-action|5|135-preAction
                // write pre-action user code here
                switchDisplayable(null, getFileList());//GEN-LINE:|18-action|6|135-postAction
                // write post-action user code here
            }//GEN-BEGIN:|18-action|7|18-postAction
        }//GEN-END:|18-action|7|18-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|18-action|8|
    //</editor-fold>//GEN-END:|18-action|8|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|24-getter|0|24-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|24-getter|0|24-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|24-getter|1|24-postInit
            // write post-init user code here
        }//GEN-BEGIN:|24-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|24-getter|2|





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: helpCommand ">//GEN-BEGIN:|46-getter|0|46-preInit
    /**
     * Returns an initiliazed instance of helpCommand component.
     * @return the initialized component instance
     */
    public Command getHelpCommand() {
        if (helpCommand == null) {//GEN-END:|46-getter|0|46-preInit
            // write pre-init user code here
            helpCommand = new Command("Help", Command.ITEM, 3);//GEN-LINE:|46-getter|1|46-postInit
            // write post-init user code here
        }//GEN-BEGIN:|46-getter|2|
        return helpCommand;
    }
    //</editor-fold>//GEN-END:|46-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: help ">//GEN-BEGIN:|50-getter|0|50-preInit
    /**
     * Returns an initiliazed instance of help component.
     * @return the initialized component instance
     */
    public Form getHelp() {
        if (help == null) {//GEN-END:|50-getter|0|50-preInit
            // write pre-init user code here
            help = new Form("Help", new Item[] { getStringItem() });//GEN-BEGIN:|50-getter|1|50-postInit
            help.addCommand(getBackCommand());
            help.setCommandListener(this);//GEN-END:|50-getter|1|50-postInit
            // write post-init user code here
        }//GEN-BEGIN:|50-getter|2|
        return help;
    }
    //</editor-fold>//GEN-END:|50-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|51-getter|0|51-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|51-getter|0|51-preInit
            // write pre-init user code here
            stringItem = new StringItem("", new HelpText().getHelpText());//GEN-LINE:|51-getter|1|51-postInit
            // write post-init user code here
        }//GEN-BEGIN:|51-getter|2|
        return stringItem;
    }
    //</editor-fold>//GEN-END:|51-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|52-getter|0|52-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|52-getter|0|52-preInit
            // write pre-init user code here
            backCommand = new Command("Back", Command.BACK, 0);//GEN-LINE:|52-getter|1|52-postInit
            // write post-init user code here
        }//GEN-BEGIN:|52-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|52-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: changePin ">//GEN-BEGIN:|56-getter|0|56-preInit
    /**
     * Returns an initiliazed instance of changePin component.
     * @return the initialized component instance
     */
    public Form getChangePin() {
        if (changePin == null) {//GEN-END:|56-getter|0|56-preInit
            // write pre-init user code here
            changePin = new Form("Change pin", new Item[] { getOldPin(), getPinTip(), getNewPin1(), getNewPin2() });//GEN-BEGIN:|56-getter|1|56-postInit
            changePin.addCommand(getOkCommand());
            changePin.addCommand(getCancelCommand());
            changePin.setCommandListener(this);//GEN-END:|56-getter|1|56-postInit
            // write post-init user code here
        }//GEN-BEGIN:|56-getter|2|
        return changePin;
    }
    //</editor-fold>//GEN-END:|56-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|57-getter|0|57-preInit
    /**
     * Returns an initiliazed instance of okCommand component.
     * @return the initialized component instance
     */
    public Command getOkCommand() {
        if (okCommand == null) {//GEN-END:|57-getter|0|57-preInit
            // write pre-init user code here
            okCommand = new Command("Ok", Command.OK, 0);//GEN-LINE:|57-getter|1|57-postInit
            // write post-init user code here
        }//GEN-BEGIN:|57-getter|2|
        return okCommand;
    }
    //</editor-fold>//GEN-END:|57-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cancelCommand ">//GEN-BEGIN:|59-getter|0|59-preInit
    /**
     * Returns an initiliazed instance of cancelCommand component.
     * @return the initialized component instance
     */
    public Command getCancelCommand() {
        if (cancelCommand == null) {//GEN-END:|59-getter|0|59-preInit
            // write pre-init user code here
            cancelCommand = new Command("Cancel", Command.CANCEL, 1);//GEN-LINE:|59-getter|1|59-postInit
            // write post-init user code here
        }//GEN-BEGIN:|59-getter|2|
        return cancelCommand;
    }
    //</editor-fold>//GEN-END:|59-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: oldPin ">//GEN-BEGIN:|64-getter|0|64-preInit
    /**
     * Returns an initiliazed instance of oldPin component.
     * @return the initialized component instance
     */
    public TextField getOldPin() {
        if (oldPin == null) {//GEN-END:|64-getter|0|64-preInit
            // write pre-init user code here
            oldPin = new TextField("Old pin", "", 32, TextField.NUMERIC | TextField.PASSWORD);//GEN-LINE:|64-getter|1|64-postInit
            // write post-init user code here
        }//GEN-BEGIN:|64-getter|2|
        return oldPin;
    }
    //</editor-fold>//GEN-END:|64-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: newPin1 ">//GEN-BEGIN:|66-getter|0|66-preInit
    /**
     * Returns an initiliazed instance of newPin1 component.
     * @return the initialized component instance
     */
    public TextField getNewPin1() {
        if (newPin1 == null) {//GEN-END:|66-getter|0|66-preInit
            // write pre-init user code here
            newPin1 = new TextField("New pin", "", 32, TextField.NUMERIC | TextField.PASSWORD);//GEN-LINE:|66-getter|1|66-postInit
            // write post-init user code here
        }//GEN-BEGIN:|66-getter|2|
        return newPin1;
    }
    //</editor-fold>//GEN-END:|66-getter|2|
    //</editor-fold>
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: newPin2 ">//GEN-BEGIN:|67-getter|0|67-preInit
    /**
     * Returns an initiliazed instance of newPin2 component.
     * @return the initialized component instance
     */
    public TextField getNewPin2() {
        if (newPin2 == null) {//GEN-END:|67-getter|0|67-preInit
            // write pre-init user code here
            newPin2 = new TextField("Confirm new pin", "", 32, TextField.NUMERIC | TextField.PASSWORD);//GEN-LINE:|67-getter|1|67-postInit
            // write post-init user code here
        }//GEN-BEGIN:|67-getter|2|
        return newPin2;
    }
    //</editor-fold>//GEN-END:|67-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pinTip ">//GEN-BEGIN:|68-getter|0|68-preInit
    /**
     * Returns an initiliazed instance of pinTip component.
     * @return the initialized component instance
     */
    public StringItem getPinTip() {
        if (pinTip == null) {//GEN-END:|68-getter|0|68-preInit
            // write pre-init user code here
            pinTip = new StringItem("Tip:", "Let blank the new pin fields if you don\'t want to be asked for it.");//GEN-BEGIN:|68-getter|1|68-postInit
            pinTip.setLayout(ImageItem.LAYOUT_DEFAULT);//GEN-END:|68-getter|1|68-postInit
            // write post-init user code here
        }//GEN-BEGIN:|68-getter|2|
        return pinTip;
    }
    //</editor-fold>//GEN-END:|68-getter|2|






    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: fileList ">//GEN-BEGIN:|87-getter|0|87-preInit
    /**
     * Returns an initiliazed instance of fileList component.
     * @return the initialized component instance
     */
    public List getFileList() {
        if (fileList == null) {//GEN-END:|87-getter|0|87-preInit
            // write pre-init user code here
            fileList = new List("Files to hide/unhide", Choice.IMPLICIT);//GEN-BEGIN:|87-getter|1|87-postInit
            fileList.addCommand(getAddCommand());
            fileList.addCommand(getBackCommand1());
            fileList.addCommand(getRemoveCommand());
            fileList.setCommandListener(this);
            fileList.setSelectCommand(getRemoveCommand());//GEN-END:|87-getter|1|87-postInit
            fillFileList(fileList);
        }//GEN-BEGIN:|87-getter|2|
        return fileList;
    }
    //</editor-fold>//GEN-END:|87-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: fileListAction ">//GEN-BEGIN:|87-action|0|87-preAction
    /**
     * Performs an action assigned to the selected list element in the fileList component.
     */
    public void fileListAction() {//GEN-END:|87-action|0|87-preAction
        // enter pre-action user code here
        String __selectedString = getFileList().getString(getFileList().getSelectedIndex());//GEN-LINE:|87-action|1|87-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|87-action|2|
    //</editor-fold>//GEN-END:|87-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|90-getter|0|90-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|90-getter|0|90-preInit
            // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 2);//GEN-LINE:|90-getter|1|90-postInit
            // write post-init user code here
        }//GEN-BEGIN:|90-getter|2|
        return backCommand1;
    }
    //</editor-fold>//GEN-END:|90-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: addCommand ">//GEN-BEGIN:|92-getter|0|92-preInit
    /**
     * Returns an initiliazed instance of addCommand component.
     * @return the initialized component instance
     */
    public Command getAddCommand() {
        if (addCommand == null) {//GEN-END:|92-getter|0|92-preInit
            // write pre-init user code here
            addCommand = new Command("Add file/directory...", Command.ITEM, 1);//GEN-LINE:|92-getter|1|92-postInit
            // write post-init user code here
        }//GEN-BEGIN:|92-getter|2|
        return addCommand;
    }
    //</editor-fold>//GEN-END:|92-getter|2|





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: removeCommand ">//GEN-BEGIN:|106-getter|0|106-preInit
    /**
     * Returns an initiliazed instance of removeCommand component.
     * @return the initialized component instance
     */
    public Command getRemoveCommand() {
        if (removeCommand == null) {//GEN-END:|106-getter|0|106-preInit
            // write pre-init user code here
            removeCommand = new Command("Remove", Command.ITEM, 0);//GEN-LINE:|106-getter|1|106-postInit
            // write post-init user code here
        }//GEN-BEGIN:|106-getter|2|
        return removeCommand;
    }
    //</editor-fold>//GEN-END:|106-getter|2|







    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: waitScreen ">//GEN-BEGIN:|122-getter|0|122-preInit
    /**
     * Returns an initiliazed instance of waitScreen component.
     * @return the initialized component instance
     */
    public WaitScreen getWaitScreen() {
        if (waitScreen == null) {//GEN-END:|122-getter|0|122-preInit
            // write pre-init user code here
            waitScreen = new WaitScreen(getDisplay());//GEN-BEGIN:|122-getter|1|122-postInit
            waitScreen.setTitle("Working...");
            waitScreen.setCommandListener(this);
            waitScreen.setImage(getHideMeLogo());
            waitScreen.setText("");
            waitScreen.setTask(getHideMeTask());//GEN-END:|122-getter|1|122-postInit
            // write post-init user code here
        }//GEN-BEGIN:|122-getter|2|
        return waitScreen;
    }
    //</editor-fold>//GEN-END:|122-getter|2|


    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: hideMeTask ">//GEN-BEGIN:|127-getter|0|127-preInit
    /**
     * Returns an initiliazed instance of hideMeTask component.
     * @return the initialized component instance
     */
    public SimpleCancellableTask getHideMeTask() {
        if (hideMeTask == null) {//GEN-END:|127-getter|0|127-preInit
            // write pre-init user code here
            hideMeTask = new SimpleCancellableTask();//GEN-BEGIN:|127-getter|1|127-execute
            hideMeTask.setExecutable(new org.netbeans.microedition.util.Executable() {
                public void execute() throws Exception {//GEN-END:|127-getter|1|127-execute
                    // write task-execution user code here
                }//GEN-BEGIN:|127-getter|2|127-postInit
            });//GEN-END:|127-getter|2|127-postInit
            // write post-init user code here
        }//GEN-BEGIN:|127-getter|3|
        return hideMeTask;
    }
    //</editor-fold>//GEN-END:|127-getter|3|
    //</editor-fold>





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pinChangedAlert ">//GEN-BEGIN:|145-getter|0|145-preInit
    /**
     * Returns an initiliazed instance of pinChangedAlert component.
     * @return the initialized component instance
     */
    public Alert getPinChangedAlert() {
        if (pinChangedAlert == null) {//GEN-END:|145-getter|0|145-preInit
            // write pre-init user code here
            pinChangedAlert = new Alert("Pin", null, null, AlertType.ALARM);//GEN-BEGIN:|145-getter|1|145-postInit
            pinChangedAlert.setTimeout(Alert.FOREVER);//GEN-END:|145-getter|1|145-postInit
            // write post-init user code here
        }//GEN-BEGIN:|145-getter|2|
        return pinChangedAlert;
    }
    //</editor-fold>//GEN-END:|145-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: changePingCommand ">//GEN-BEGIN:|141-getter|0|141-preInit
    /**
     * Returns an initiliazed instance of changePingCommand component.
     * @return the initialized component instance
     */
    public Command getChangePingCommand() {
        if (changePingCommand == null) {//GEN-END:|141-getter|0|141-preInit
            // write pre-init user code here
            changePingCommand = new Command("Change pin...", Command.ITEM, 2);//GEN-LINE:|141-getter|1|141-postInit
            // write post-init user code here
        }//GEN-BEGIN:|141-getter|2|
        return changePingCommand;
    }
    //</editor-fold>//GEN-END:|141-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pinForm ">//GEN-BEGIN:|150-getter|0|150-preInit
    /**
     * Returns an initiliazed instance of pinForm component.
     * @return the initialized component instance
     */
    public Form getPinForm() {
        if (pinForm == null) {//GEN-END:|150-getter|0|150-preInit
            // write pre-init user code here
            pinForm = new Form("Enter pin", new Item[] { getSpacer(), getPinFormString(), getPin() });//GEN-BEGIN:|150-getter|1|150-postInit
            pinForm.addCommand(getOkCommand1());
            pinForm.addCommand(getExitCommand1());
            pinForm.setCommandListener(this);//GEN-END:|150-getter|1|150-postInit
            // write post-init user code here
        }//GEN-BEGIN:|150-getter|2|
        return pinForm;
    }
    //</editor-fold>//GEN-END:|150-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: spacer ">//GEN-BEGIN:|152-getter|0|152-preInit
    /**
     * Returns an initiliazed instance of spacer component.
     * @return the initialized component instance
     */
    public Spacer getSpacer() {
        if (spacer == null) {//GEN-END:|152-getter|0|152-preInit
            // write pre-init user code here
            spacer = new Spacer(16, 1);//GEN-LINE:|152-getter|1|152-postInit
            // write post-init user code here
        }//GEN-BEGIN:|152-getter|2|
        return spacer;
    }
    //</editor-fold>//GEN-END:|152-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pinFormString ">//GEN-BEGIN:|153-getter|0|153-preInit
    /**
     * Returns an initiliazed instance of pinFormString component.
     * @return the initialized component instance
     */
    public StringItem getPinFormString() {
        if (pinFormString == null) {//GEN-END:|153-getter|0|153-preInit
            // write pre-init user code here
            pinFormString = new StringItem("", "This application is protected.");//GEN-LINE:|153-getter|1|153-postInit
            // write post-init user code here
        }//GEN-BEGIN:|153-getter|2|
        return pinFormString;
    }
    //</editor-fold>//GEN-END:|153-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: pin ">//GEN-BEGIN:|154-getter|0|154-preInit
    /**
     * Returns an initiliazed instance of pin component.
     * @return the initialized component instance
     */
    public TextField getPin() {
        if (pin == null) {//GEN-END:|154-getter|0|154-preInit
            // write pre-init user code here
            pin = new TextField("Enter pin", null, 32, TextField.NUMERIC | TextField.PASSWORD);//GEN-LINE:|154-getter|1|154-postInit
            // write post-init user code here
        }//GEN-BEGIN:|154-getter|2|
        return pin;
    }
    //</editor-fold>//GEN-END:|154-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 ">//GEN-BEGIN:|155-getter|0|155-preInit
    /**
     * Returns an initiliazed instance of okCommand1 component.
     * @return the initialized component instance
     */
    public Command getOkCommand1() {
        if (okCommand1 == null) {//GEN-END:|155-getter|0|155-preInit
            // write pre-init user code here
            okCommand1 = new Command("Ok", Command.OK, 0);//GEN-LINE:|155-getter|1|155-postInit
            // write post-init user code here
        }//GEN-BEGIN:|155-getter|2|
        return okCommand1;
    }
    //</editor-fold>//GEN-END:|155-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">//GEN-BEGIN:|157-getter|0|157-preInit
    /**
     * Returns an initiliazed instance of exitCommand1 component.
     * @return the initialized component instance
     */
    public Command getExitCommand1() {
        if (exitCommand1 == null) {//GEN-END:|157-getter|0|157-preInit
            // write pre-init user code here
            exitCommand1 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|157-getter|1|157-postInit
            // write post-init user code here
        }//GEN-BEGIN:|157-getter|2|
        return exitCommand1;
    }
    //</editor-fold>//GEN-END:|157-getter|2|
    //</editor-fold>



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: hideMeLogo ">//GEN-BEGIN:|162-getter|0|162-preInit
    /**
     * Returns an initiliazed instance of hideMeLogo component.
     * @return the initialized component instance
     */
    public Image getHideMeLogo() {
        if (hideMeLogo == null) {//GEN-END:|162-getter|0|162-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|162-getter|1|162-@java.io.IOException
                hideMeLogo = Image.createImage("/images/hideme.png");
            } catch (java.io.IOException e) {//GEN-END:|162-getter|1|162-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|162-getter|2|162-postInit
            // write post-init user code here
        }//GEN-BEGIN:|162-getter|3|
        return hideMeLogo;
    }
    //</editor-fold>//GEN-END:|162-getter|3|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: hideMeBrowser ">//GEN-BEGIN:|170-getter|0|170-preInit
    /**
     * Returns an initiliazed instance of hideMeBrowser component.
     * @return the initialized component instance
     */
    public HideMeBrowser getHideMeBrowser() {
        if (hideMeBrowser == null) {//GEN-END:|170-getter|0|170-preInit
            // write pre-init user code here
            hideMeBrowser = new HideMeBrowser();//GEN-BEGIN:|170-getter|1|170-postInit
            hideMeBrowser.setTitle("hideMeBrowser");
            hideMeBrowser.addCommand(getBackCommand2());
            hideMeBrowser.setCommandListener(this);
            hideMeBrowser.setCommandListener(this);//GEN-END:|170-getter|1|170-postInit
            // write post-init user code here
        }//GEN-BEGIN:|170-getter|2|
        return hideMeBrowser;
    }
    //</editor-fold>//GEN-END:|170-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: hideMeBrowserAction ">//GEN-BEGIN:|170-action|0|170-preAction
    /**
     * Performs an action assigned to the selected list element in the hideMeBrowser component.
     */
    public void hideMeBrowserAction() {//GEN-END:|170-action|0|170-preAction
        // enter pre-action user code here
        String __selectedString = getHideMeBrowser().getString(getHideMeBrowser().getSelectedIndex());//GEN-LINE:|170-action|1|170-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|170-action|2|
    //</editor-fold>//GEN-END:|170-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand2 ">//GEN-BEGIN:|177-getter|0|177-preInit
    /**
     * Returns an initiliazed instance of backCommand2 component.
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {//GEN-END:|177-getter|0|177-preInit
            // write pre-init user code here
            backCommand2 = new Command("Back", Command.BACK, 3);//GEN-LINE:|177-getter|1|177-postInit
            // write post-init user code here
        }//GEN-BEGIN:|177-getter|2|
        return backCommand2;
    }
    //</editor-fold>//GEN-END:|177-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: fileAddedAlert ">//GEN-BEGIN:|182-getter|0|182-preInit
    /**
     * Returns an initiliazed instance of fileAddedAlert component.
     * @return the initialized component instance
     */
    public Alert getFileAddedAlert() {
        if (fileAddedAlert == null) {//GEN-END:|182-getter|0|182-preInit
            // write pre-init user code here
            fileAddedAlert = new Alert("File added", "<null>", null, AlertType.INFO);//GEN-BEGIN:|182-getter|1|182-postInit
            fileAddedAlert.setTimeout(3000);//GEN-END:|182-getter|1|182-postInit
            // write post-init user code here
        }//GEN-BEGIN:|182-getter|2|
        return fileAddedAlert;
    }
    //</editor-fold>//GEN-END:|182-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: empty_list ">//GEN-BEGIN:|183-getter|0|183-preInit
    /**
     * Returns an initiliazed instance of empty_list component.
     * @return the initialized component instance
     */
    public Alert getEmpty_list() {
        if (empty_list == null) {//GEN-END:|183-getter|0|183-preInit
            // write pre-init user code here
            empty_list = new Alert("Error", "File list is empty. Please, fill the list first.", null, AlertType.ERROR);//GEN-BEGIN:|183-getter|1|183-postInit
            empty_list.setTimeout(Alert.FOREVER);//GEN-END:|183-getter|1|183-postInit
            // write post-init user code here
        }//GEN-BEGIN:|183-getter|2|
        return empty_list;
    }
    //</editor-fold>//GEN-END:|183-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: error_hidding ">//GEN-BEGIN:|184-getter|0|184-preInit
    /**
     * Returns an initiliazed instance of error_hidding component.
     * @return the initialized component instance
     */
    public Alert getError_hidding() {
        if (error_hidding == null) {//GEN-END:|184-getter|0|184-preInit
            // write pre-init user code here
            error_hidding = new Alert("Error", "Erro hiding files", null, AlertType.ERROR);//GEN-BEGIN:|184-getter|1|184-postInit
            error_hidding.setTimeout(Alert.FOREVER);//GEN-END:|184-getter|1|184-postInit
            // write post-init user code here
        }//GEN-BEGIN:|184-getter|2|
        return error_hidding;
    }
    //</editor-fold>//GEN-END:|184-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: success_hidding ">//GEN-BEGIN:|185-getter|0|185-preInit
    /**
     * Returns an initiliazed instance of success_hidding component.
     * @return the initialized component instance
     */
    public Alert getSuccess_hidding() {
        if (success_hidding == null) {//GEN-END:|185-getter|0|185-preInit
            // write pre-init user code here
            success_hidding = new Alert("Operation succesful", "Files hidden succesfully!", null, AlertType.CONFIRMATION);//GEN-BEGIN:|185-getter|1|185-postInit
            success_hidding.setTimeout(Alert.FOREVER);//GEN-END:|185-getter|1|185-postInit
            // write post-init user code here
            success_hidding.setCommandListener(new CommandListener(){
                public void commandAction(Command c, Displayable d) {
                    exitMIDlet();
                }
            }
            );
        }//GEN-BEGIN:|185-getter|2|
        return success_hidding;
    }
    //</editor-fold>//GEN-END:|185-getter|2|







    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay () {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable (null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
            startMIDlet ();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }

    private void deleteFile(int index){
        if(index >= 0){
            FileList fl = new FileList();
            //fl.remove(recordIds.remove(new Integer(index)));
            fl.remove(recordIds.elementAt(index));
            recordIds.removeElementAt(index);
            fileList.delete(index);
            if(fileList.size() == 0){
                fileList.removeCommand(removeCommand);
            }
        }
    }

    private void fillFileList(List fileList){
        FileList fl = new FileList();
        Enumeration e = fl.keys();
        Integer recordId, listId;
        while(e.hasMoreElements()){
            recordId = (Integer) e.nextElement();
            //listId = new Integer(fileList.append((String) fl.get(recordId), null));
            //recordIds.put(listId, recordId);
            fileList.append((String) fl.get(recordId), null);
            recordIds.addElement(recordId);
        }
        if(fileList.size() == 0){
                fileList.removeCommand(removeCommand);
        }
    }

    public void addSelected(String file){
        FileList fl = new FileList();
        int storeId = fl.add(file);
        fileList.append(file, null);
        recordIds.addElement(new Integer(storeId));
        if(fileList.size() == 1){
            fileList.addCommand(removeCommand);
        }
    }
}